//
//  productCenterVC.m
//  BeautyPicture
//
//  Created by 沈振邦 on 15/9/7.
//  Copyright (c) 2015年 szb. All rights reserved.
//

#import "orderCenterVC.h"
#import "cellBaseModel.h"
#import "childBaseTableViewCell.h"
#import "BPhttpTool.h"
#import "AccountTool.h"
#import "MJExtension.h"
#import "indentModel.h"
#import "AppDelegate.h"
#import "shaidanViewController.h"
#import "MBProgressHUD+MJ.h"
#import "wuliuVC.h"
#import "FourButton.h"
#import "FourUIView.h"
#import "ReceiptTableViewCell.h"
#import "AppDelegate.h"
#import "PayOverSuccessViewController.h"
#import "BPLoginViewController.h"



@interface orderCenterVC ()<childBaseTableViewCellDelegate,ReceiptTableViewCellDelegate,UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>{
    BOOL _isfirst;
    FourButton *_btn;
    FourUIView *_viewFour;
}

@property (nonatomic,strong)AppDelegate *delegates;

@property (nonatomic, assign) BOOL Kong;

//等待付款
@property (nonatomic,strong)NSMutableArray *waitPayArry;
//等待收货
@property (nonatomic,strong)NSMutableArray *ReceivingArry;
//已收货
@property (nonatomic,strong)NSMutableArray *receivedArry;
//待晒单
@property (nonatomic,strong)NSMutableArray *showProductArry;
// 待收货
@property (nonatomic,strong)NSMutableArray *DaiShouhuoArray;

//@property (nonatomic, strong) UIView *ui;
@property (nonatomic, strong) NSArray *buttonImag;
@property (nonatomic, strong) NSArray *buttonIm;

@property (nonatomic, strong) NSArray *buttonName;
@property (nonatomic, strong) UITapGestureRecognizer *tapOne;


@property (nonatomic, strong) UIButton *aa;
@property (nonatomic, strong) UILabel *labelaa;
@property (nonatomic, strong) UIImageView *imageaa;

@property (nonatomic, strong) UIButton *bb;
@property (nonatomic, strong) UILabel *labelbb;
@property (nonatomic, strong) UIImageView *imagebb;

@property (nonatomic, strong) UIButton *cc;
@property (nonatomic, strong) UILabel *labelcc;
@property (nonatomic, strong) UIImageView *imagecc;

@property (nonatomic, strong) UIButton *dd;
@property (nonatomic, strong) UILabel *labeldd;
@property (nonatomic, strong) UIImageView *imagedd;


@property (nonatomic, strong) UILabel *daiFukuanLabel;
@property (nonatomic, strong) UILabel *yinShuaLabel;
@property (nonatomic, strong) UILabel *daishouLabel;
@property (nonatomic, strong) UILabel *yishouLabel;
@end

@implementation orderCenterVC

- (void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBarHidden = YES;
    [self getOrderData];
}

- (void)viewWillDisappear:(BOOL)animated{
    self.navigationController.navigationBarHidden = NO;
}


- (void)creat{
    CGFloat imX = 20;
    CGFloat imY = 30;
    CGFloat imW = 20;
    CGFloat imH = 20;
    
    UIButton *top = [[UIButton alloc] initWithFrame:CGRectMake(imX, imY, imW, imH)];
//    top.image = [UIImage imageNamed:@"返回"];
    [top setBackgroundImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [top addTarget:self action:@selector(top:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:top];
    
    CGFloat laX = self.view.frame.size.width / 2 - 50;
    CGFloat laW = 100;
    CGFloat laH = 40;
    UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(laX, imY - 10, laW, laH)];
    name.text = @"我的订单";
    name.font = [UIFont systemFontOfSize:21];
    name.textColor = BPFenHongColor;
    [self.view addSubview:name];
    
    
    UIImageView *longL = [[UIImageView alloc] initWithFrame:CGRectMake(0, imY + 30, self.view.frame.size.width, 5)];
    longL.image = [UIImage imageNamed:@"波纹线"];
    [self.view addSubview:longL];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.Kong = YES;
    
    self.buttonName = [NSArray arrayWithObjects:@"待付款",@"印刷中",@"待收货", @"已收货",nil];
    self.buttonImag = [NSArray arrayWithObjects:@"MydaiOrder",@"MyyinShua",@"MydaiShou",@"MyhuoOver" , nil];
    
    _isfirst = YES;
    _waitPayArry = [NSMutableArray array];
    _ReceivingArry = [NSMutableArray array];
    _receivedArry = [NSMutableArray array];
    _showProductArry = [NSMutableArray array];
    _DaiShouhuoArray = [NSMutableArray array];
    
    // 不注释掉会走 2 次,会弹出两次 alert 框框.
   // [self getOrderData];
    
    

    [self creat];
    // Do any additional setup after loading the view.
}



- (void)getOrderData
{
//    if ([AccountTool account].uid == nil) {
////        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您还没有登录" delegate:self cancelButtonTitle:@"去登录~" otherButtonTitles:nil, nil];
////        [alert show];
//        [MBProgressHUD showError:@"您还没有登录!"];
//        BPLoginViewController *logo = [[BPLoginViewController alloc] init];
//        logo.block = ^(){
//            NSLog(@"ggg");
//        };
//        [self.navigationController pushViewController:logo animated:YES];
//    }else{
    
    [BPhttpTool get:[NSString stringWithFormat:@"%@order/orderlist/uid/%@",BPhttp,[AccountTool account].uid] params:nil success:^(id responseObj) {
       
        NSLog(@"我的订单数据= %@", responseObj);
        
        if (responseObj == nil) {
            
            /* 删除多余 的 子试图 */
            [self.view.subviews[0] removeFromSuperview];
            [self createKongOrder];
            
        }
        else{
            
            [self setUpTableView];
            [self addTopButton];
            // 待付款=100;
            // 印刷中=200,300;
            // 待收货=400;
            // 已收货=500.
            NSArray *arry = [indentModel objectArrayWithKeyValuesArray:responseObj];
            
            for (indentModel *model in arry) {
                int number = [model.status intValue];
                if (number == 100) {
                  //  NSLog(@"self.waitPayArry.count = %ld", self.waitPayArry.count);
                    [self.waitPayArry addObject:model];
                }
                else if (number == 400){
                  //  NSLog(@"self.DaiShouhuoArray.count = %ld", self.DaiShouhuoArray.count);
                    [self.DaiShouhuoArray addObject:model];
                }
                else if (number == 200 || number == 300){
                  //  NSLog(@"self.ReceivingArry.count = %ld", self.ReceivingArry.count);
                    [self.ReceivingArry addObject:model];
                    
                }else if (number == 500){
                  //  NSLog(@"self.receivedArry.count = %ld", self.receivedArry.count);
//                    if ([model.isshare intValue] == 0) {
//                        [self.showProductArry addObject:model];
//                    }else{
                        [self.receivedArry addObject:model];
//                    }
                    
                }
            }
            if (_isfirst == YES) {
                _isfirst = NO;
                
                if (self.waitPayArry.count == 0) {
                    self.daiFukuanLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.orderTableView.frame.size.width / 2 - 50, self.orderTableView.frame.size.height / 2 - 45, 100, 30)];
                    self.daiFukuanLabel.backgroundColor = [UIColor clearColor];
                    self.daiFukuanLabel.font = [UIFont systemFontOfSize:20];
                    self.daiFukuanLabel.alpha = 0.7;
                    self.daiFukuanLabel.text = @"暂无订单";
                    [self.orderTableView addSubview:self.daiFukuanLabel];
                }else{
                    self.dataArray = self.waitPayArry;
                    [self.orderTableView reloadData];
                }
            }
            
        }
        
    } failure:^(NSError *error) {
        BPLog(@"获取失败");
        /* 删除多余 的 子试图 */
        [self.view.subviews[0] removeFromSuperview];
        [self createKongOrder];
        NSLog(@"失败%@", error);
    }];
//    }
}


//- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//    BPLoginViewController *logo = [[BPLoginViewController alloc] init];
//    logo.block = ^(){
//        NSLog(@"ggg");
//    };
//    [self.navigationController pushViewController:logo animated:YES];
//}


// 如果 返回的数据为空的话
- (void)createKongOrder{
    
    CGFloat ImX = self.view.frame.size.width / 2 - 100.0f;
    CGFloat ImY = 130.0f;
    CGFloat ImW = ImX + 120.0f;
    CGFloat ImH = ImX + 120.0f;
    
    UIImageView *images = [[UIImageView alloc]initWithFrame:CGRectMake(ImX + 10.0f, ImY, ImW, ImH)];
    images.image = [UIImage imageNamed:@"logoKong"];
    [self.view addSubview:images];
    
    CGFloat LabH = 40.0f;
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(ImX - 10.0f, ImY + ImH + 50.0f, ImW + 50.0f, LabH)];
    label.text = @"您还没有订单 , 赶紧去定制一个吧~";
    label.numberOfLines = 0;
    label.font = [UIFont systemFontOfSize:13];
    label.alpha = 0.5;
    [self.view addSubview:label];
    
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(ImX + 10.0f, ImY + ImH + 110.0f, ImW, LabH)];
    button.backgroundColor = BPGlobaThemeColor;
    [button setTitle:@"马上制作" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.layer.cornerRadius = 20;
    button.layer.masksToBounds = YES;
    [button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (void)button:(UIButton *)button{
    [self.navigationController popToRootViewControllerAnimated:YES];
}




- (void)setUpTableView{
    
    CGFloat tableViewY = BPScreenNavY + 50.0f;
    UITableView *orderTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, tableViewY, BPScreenW, BPScreenH - tableViewY)];
    orderTableView.backgroundColor = [UIColor whiteColor];
    orderTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    orderTableView.delegate = self;
    orderTableView.dataSource = self;
    orderTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:orderTableView];
    self.orderTableView = orderTableView;
}

- (void)addTopButton{
    
    
    /* 第一个按钮 */
    self.aa = [UIButton buttonWithType:UIButtonTypeCustom];
    self.aa.tag = 1001;
    CGFloat btnW = BPScreenW / 4.0f;
    [self.aa addTarget:self action:@selector(buttonOne:) forControlEvents:UIControlEventTouchUpInside];
    self.aa.frame = CGRectMake(0, 0, btnW, self.headView.height);
    BPLineView *line = [[BPLineView alloc] initWithFrame:CGRectMake(btnW * (0 + 1), 10, 1, self.aa.height - 20)];
    
    [self.headView addSubview:line];
    [self.headView addSubview:self.aa];
    
    
    _labelaa = [[UILabel alloc] initWithFrame:CGRectMake(self.aa.frame.size.width / 2 - 15, 30, 30, 10)];
    _labelaa.font = [UIFont systemFontOfSize:10];
//    _labelaa.textColor = BPFenHongColor;
    _labelaa.textColor = [UIColor blackColor];
    _labelaa.text = self.buttonName[0];
    [self.aa addSubview:_labelaa];
    
    _imageaa = [[UIImageView alloc] initWithFrame:CGRectMake(self.aa.frame.size.width / 2 - 10, 5, 20, 20)];
    _imageaa.image = [UIImage imageNamed:@"MydaiOrder-over"];
    [self.aa addSubview:_imageaa];
    
    /* 第二个按钮 */
    self.bb = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.bb.tag = 1002;
    [self.bb addTarget:self action:@selector(buttonTwo:) forControlEvents:UIControlEventTouchUpInside];
    self.bb.frame = CGRectMake(btnW * 1, 0, btnW, self.headView.height);
    BPLineView *lineTwo = [[BPLineView alloc] initWithFrame:CGRectMake(btnW * (1 + 1), 10, 1, self.bb.height - 20)];
    
    [self.headView addSubview:lineTwo];
    [self.headView addSubview:self.bb];
    
    
    self.labelbb = [[UILabel alloc] initWithFrame:CGRectMake(self.bb.frame.size.width / 2 - 15, 30, 30, 10)];
    self.labelbb.font = [UIFont systemFontOfSize:10];
    self.labelbb.text = self.buttonName[1];
    _labelbb.textColor = BPFenHongColor;
    [self.bb addSubview:self.labelbb];
    
    self.imagebb = [[UIImageView alloc] initWithFrame:CGRectMake(self.bb.frame.size.width / 2 - 10, 5, 20, 20)];
    self.imagebb.image = [UIImage imageNamed:self.buttonImag[1]];
    [self.bb addSubview:self.imagebb];
    
    
    /* 第三个按钮 */
    self.cc = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.cc.tag = 1003;
    [self.cc addTarget:self action:@selector(buttonThree:) forControlEvents:UIControlEventTouchUpInside];
    self.cc.frame = CGRectMake(btnW * 2, 0, btnW, self.headView.height);
    BPLineView *lineThree = [[BPLineView alloc] initWithFrame:CGRectMake(btnW * (2 + 1), 10, 1, self.cc.height - 20)];
    
    [self.headView addSubview:lineThree];
    [self.headView addSubview:self.cc];
    
    
    self.labelcc = [[UILabel alloc] initWithFrame:CGRectMake(self.cc.frame.size.width / 2 - 15, 30, 30, 10)];
    self.labelcc.font = [UIFont systemFontOfSize:10];
    self.labelcc.text = self.buttonName[2];
    _labelcc.textColor = BPFenHongColor;
    [self.cc addSubview:self.labelcc];
    
    self.imagecc = [[UIImageView alloc] initWithFrame:CGRectMake(self.cc.frame.size.width / 2 - 10, 5, 20, 20)];
    self.imagecc.image = [UIImage imageNamed:self.buttonImag[2]];
    [self.cc addSubview:self.imagecc];
    
    
    /* 第四个按钮 */
    self.dd = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.dd.tag = 1004;
    [self.dd addTarget:self action:@selector(buttonFour:) forControlEvents:UIControlEventTouchUpInside];
    self.dd.frame = CGRectMake(btnW * 3, 0, btnW, self.headView.height);
    BPLineView *lineFour = [[BPLineView alloc] initWithFrame:CGRectMake(btnW * (3 + 1), 10, 1, self.cc.height - 20)];
    
    [self.headView addSubview:lineFour];
    [self.headView addSubview:self.dd];
    
    
    self.labeldd = [[UILabel alloc] initWithFrame:CGRectMake(self.dd.frame.size.width / 2 - 15, 30, 30, 10)];
    self.labeldd.font = [UIFont systemFontOfSize:10];
    self.labeldd.text = self.buttonName[3];
    _labeldd.textColor = BPFenHongColor;
    [self.dd addSubview:self.labeldd];
    
    self.imagedd = [[UIImageView alloc] initWithFrame:CGRectMake(self.dd.frame.size.width / 2 - 10, 5, 20, 20)];
    self.imagedd.image = [UIImage imageNamed:self.buttonImag[3]];
    [self.dd addSubview:self.imagedd];
}



- (void)buttonOne:(UIButton *)buttonOn{
    [self.yishouLabel removeFromSuperview];
    [self.yinShuaLabel removeFromSuperview];
    [self.daishouLabel removeFromSuperview];
    
    self.aa.tag = 1001;
    self.bb.tag = 1;
    self.cc.tag = 1;
    self.dd.tag = 1;
    self.labelaa.textColor = [UIColor blackColor];
    self.labelbb.textColor = BPFenHongColor;
    self.labelcc.textColor = BPFenHongColor;
    self.labeldd.textColor = BPFenHongColor;
    
    self.imagebb.image = [UIImage imageNamed:@"MyyinShua"];
    self.imagecc.image = [UIImage imageNamed:@"MydaiShou"];
    self.imagedd.image = [UIImage imageNamed:@"MyhuoOver"];
    
    self.imageaa.image = [UIImage imageNamed:@"MydaiOrder-over"];
    
    if (self.waitPayArry.count == 0 && self.aa.tag == 1001) {
        self.daiFukuanLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.orderTableView.frame.size.width / 2 - 50, self.orderTableView.frame.size.height / 2 - 45, 100, 30)];
        self.daiFukuanLabel.backgroundColor = [UIColor clearColor];
        self.daiFukuanLabel.font = [UIFont systemFontOfSize:20];
        self.daiFukuanLabel.alpha = 0.7;
        self.daiFukuanLabel.text = @"暂无订单";
        [self.orderTableView addSubview:self.daiFukuanLabel];
    }else{
        [self.daiFukuanLabel removeFromSuperview];
    }

    
    self.dataArray = self.waitPayArry;
    [self.orderTableView reloadData];
    
}


- (void)buttonTwo:(UIButton *)buttonTw{
    
    [self.daiFukuanLabel removeFromSuperview];
    [self.yishouLabel removeFromSuperview];
    [self.daishouLabel removeFromSuperview];
    
    self.aa.tag = 1;
    self.bb.tag = 1002;
    self.cc.tag = 1;
    self.dd.tag = 1;

    self.labelaa.textColor = BPFenHongColor;
    self.labelbb.textColor = [UIColor blackColor];
    self.labelcc.textColor = BPFenHongColor;
    self.labeldd.textColor = BPFenHongColor;
    
    self.imageaa.image = [UIImage imageNamed:@"MydaiOrder"];
    self.imagecc.image = [UIImage imageNamed:@"MydaiShou"];
    self.imagedd.image = [UIImage imageNamed:@"MyhuoOver"];
    self.imagebb.image = [UIImage imageNamed:@"MyyinShua-over"];

    
    if (self.ReceivingArry.count == 0 && self.bb.tag == 1002) {
        self.yinShuaLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.orderTableView.frame.size.width / 2 - 50, self.orderTableView.frame.size.height / 2 - 45, 100, 30)];
        self.yinShuaLabel.backgroundColor = [UIColor clearColor];
        self.yinShuaLabel.font = [UIFont systemFontOfSize:20];
        self.yinShuaLabel.alpha = 0.7;
        self.yinShuaLabel.text = @"暂无订单";
        [self.orderTableView addSubview:self.yinShuaLabel];
    }else{
        [self.yinShuaLabel removeFromSuperview];
    }
   
    self.dataArray = self.ReceivingArry;
    [self.orderTableView reloadData];
    
    
}

- (void)buttonThree:(UIButton *)buttonTw{
    
   [self.daiFukuanLabel removeFromSuperview];
    [self.yishouLabel removeFromSuperview];
   [self.yinShuaLabel removeFromSuperview];

    self.aa.tag = 1;
    self.bb.tag = 1;
    self.cc.tag = 1003;
    self.dd.tag = 1;

    self.labelaa.textColor = BPFenHongColor;
    self.labelbb.textColor = BPFenHongColor;
    self.labelcc.textColor = [UIColor blackColor];
    self.labeldd.textColor = BPFenHongColor;
    
    self.imageaa.image = [UIImage imageNamed:@"MydaiOrder"];
    self.imagebb.image = [UIImage imageNamed:@"MyyinShua"];
    self.imagedd.image = [UIImage imageNamed:@"MyhuoOver"];
    self.imagecc.image = [UIImage imageNamed:@"MydaiShou-over"];
    
    
    if (self.cc.tag == 1003 && self.DaiShouhuoArray.count == 0) {
        self.daishouLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.orderTableView.frame.size.width / 2 - 50, self.orderTableView.frame.size.height / 2 - 45, 100, 30)];
        self.daishouLabel.backgroundColor = [UIColor clearColor];
        self.daishouLabel.font = [UIFont systemFontOfSize:20];
        self.daishouLabel.alpha = 0.7;
        self.daishouLabel.text = @"暂无订单";
        [self.orderTableView addSubview:self.daishouLabel];
    }else{
        [self.daishouLabel removeFromSuperview];
    }
    
    self.dataArray = self.DaiShouhuoArray;
    [self.orderTableView reloadData];
}

- (void)buttonFour:(UIButton *)buttonTw{
    
    [self.daiFukuanLabel removeFromSuperview];
    [self.yinShuaLabel removeFromSuperview];
    [self.daishouLabel removeFromSuperview];
    
    self.aa.tag = 1;
    self.bb.tag = 1;
    self.cc.tag = 1;
    self.dd.tag = 1004;
    self.labelaa.textColor = BPFenHongColor;
    self.labelbb.textColor = BPFenHongColor;
    self.labelcc.textColor =BPFenHongColor;
    self.labeldd.textColor =[UIColor blackColor];
    
    self.imageaa.image = [UIImage imageNamed:@"MydaiOrder"];
    self.imagebb.image = [UIImage imageNamed:@"MyyinShua"];
    self.imagecc.image = [UIImage imageNamed:@"MydaiShou"];
    self.imagedd.image = [UIImage imageNamed:@"MyhuoOver-over"];
    
    
    if (self.dd.tag == 1004 && self.receivedArry.count == 0) {
        self.yishouLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.orderTableView.frame.size.width / 2 - 50, self.orderTableView.frame.size.height / 2 - 45, 100, 30)];
        self.yishouLabel.backgroundColor = [UIColor clearColor];
        self.yishouLabel.font = [UIFont systemFontOfSize:20];
        self.yishouLabel.alpha = 0.7;
        self.yishouLabel.text = @"暂无订单";
        [self.orderTableView addSubview:self.yishouLabel];
    }else{
        [self.yishouLabel removeFromSuperview];
    }
    
    self.dataArray = self.receivedArry;
    [self.orderTableView reloadData];
}

//- (void)addLabelTitle{
//    
//    self.yishouLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.orderTableView.frame.size.width / 2 - 50, self.orderTableView.frame.size.height / 2 - 45, 100, 30)];
//    self.yishouLabel.backgroundColor = [UIColor clearColor];
//    self.yishouLabel.font = [UIFont systemFontOfSize:20];
//    self.yishouLabel.alpha = 0.7;
//    self.yishouLabel.text = @"暂无订单";
//    [self.orderTableView addSubview:self.yishouLabel];
//    
//}


//- (void)addTopButton{
//    NSArray *buttonName = [NSArray arrayWithObjects:@"待付款",@"印刷中",@"待收货", @"已收货",nil];
//    self.buttonImag = [NSArray arrayWithObjects:@"MydaiOrder",@"MyyinShua",@"MydaiShou",@"MyhuoOver" , nil];
//    
//    for (int i = 0; i < 4; i ++) {
//        
//        _btn = [FourButton buttonWithType:UIButtonTypeCustom];
//        _btn.tag = 1000+i;
//        CGFloat btnW = BPScreenW / 4.0f;
//        _btn.frame = CGRectMake(btnW * i , 0, btnW, self.headView.height);
//        BPLineView *line = [[BPLineView alloc] initWithFrame:CGRectMake(btnW * (i + 1), 10, 1, _btn.height - 20)];
//        //[btn setTitle:buttonName[i] forState:UIControlStateNormal];
//        //[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        //btn.titleLabel.font = [UIFont systemFontOfSize:13.0f];
//        //btn.titleLabel.textAlignment = NSTextAlignmentCenter;
//        [_btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
//        [self.headView addSubview:line];
//        [self.headView addSubview:_btn];
//        
//        
//        _btn.label = [[UILabel alloc] initWithFrame:CGRectMake(_btn.frame.size.width / 2 - 15, 30, 30, 10)];
//        _btn.label.font = [UIFont systemFontOfSize:10];
//        _btn.label.text = buttonName[i];
//        [_btn addSubview:_btn.label];
//        
//        _btn.imageS = [[UIImageView alloc] initWithFrame:CGRectMake(_btn.frame.size.width / 2 - 10, 5, 20, 20)];
//        _btn.imageS.image = [UIImage imageNamed:self.buttonImag[i]];
//        _btn.imageS.tag = _btn.tag;
//        [_btn addSubview:_btn.imageS];
//        
//        //        if (_btn.num == 0) {
//        //            [self btnClick:_btn];
//        //        }
//        
//    }
//}
//
//
//- (void)btnClick:(UIButton *)button
//{
//    button.selected = !button.selected;
//    if (button.tag == 1000) {
//        if (button.selected == YES) {
//            _btn.imageS.image = [UIImage imageNamed:@"MydaiOrder"];
//        }else{
//             _btn.imageS.image = [UIImage imageNamed:@"MydaiOrder-over"];
//        }
//        self.dataArray = self.waitPayArry;
//        [self.orderTableView reloadData];
//        
//    }else if (button.tag == 1001){
//        
//        
//        if (button.selected == YES) {
//            _btn.imageS.image = [UIImage imageNamed:@"MyyinShua"];
//        }else{
//            _btn.imageS.image = [UIImage imageNamed:@"MyyinShua-over"];
//        }
//        
//        self.dataArray = self.ReceivingArry;
//        [self.orderTableView reloadData];
//    }else if (button.tag == 1002){
//        
//        
//        if (button.selected == YES) {
//            _btn.imageS.image = [UIImage imageNamed:@"MydaiShou"];
//        }else{
//            _btn.imageS.image = [UIImage imageNamed:@"MydaiShou-over"];
//        }
//        
//        self.dataArray = self.showProductArry;
//        [self.orderTableView reloadData];
//    }else{
//        
//        if (button.selected == YES) {
//            _btn.imageS.image = [UIImage imageNamed:@"MyhuoOver"];
//        }else{
//            _btn.imageS.image = [UIImage imageNamed:@"MyhuoOver-over"];
//        }
//        
//        self.dataArray = self.receivedArry;
//        [self.orderTableView reloadData];
//    }
//}




- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (self.cc.tag == 1003) {
        
        ReceiptTableViewCell *cell = [ReceiptTableViewCell cellWithTableView:tableView];
        
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.delegate = self;
        cell.qianshou.text = @"发货日期:";
        [cell setUpCell22:self.dataArray[indexPath.row]];
       
        return cell;
        
    }else if (self.dd.tag == 1004){
        ReceiptTableViewCell *cell = [ReceiptTableViewCell cellWithTableView:tableView];
        
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.delegate = self;
        cell.qianshou.text = @"收货日期:";
        [cell setUpCellTow:self.dataArray[indexPath.row]];
        return cell;
    }
    else{
        childBaseTableViewCell *cell = [childBaseTableViewCell cellWithTableView:tableView];
        
        cell.backgroundColor = [UIColor clearColor];
        
        cell.delegate = self;
        
        [cell setUpCell2:self.dataArray[indexPath.row]];
        
        return cell;
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (self.cc.tag == 1003) {
        return 230;
    }
    if (self.dd.tag == 1004) {
        return 230;
    }
    else{
        
        return 140;
    }
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_aa.tag == 1001) {
        
        indentModel *model = self.dataArray[indexPath.row];
        [D_Main_Appdelegate showPayView];
       // [[D_Main_Appdelegate payView] setUpHeadView:model.orderid];
        [D_Main_Appdelegate payView].orderNumber = model.orderid;
        [D_Main_Appdelegate payView].price = model.total;
        [D_Main_Appdelegate payView].block =^{
            [self.waitPayArry removeObject:model];
            model.status = @"200";
            [self.ReceivingArry addObject:model];
            [self.orderTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
        };
    }
}


//马上付钱
- (void)quicklyPay:(childBaseTableViewCell *)childBaseCell
{
    NSIndexPath *indexPath = [self.orderTableView indexPathForCell:childBaseCell];
    indentModel *model = self.dataArray[indexPath.row];
    [D_Main_Appdelegate showPayView];
//    [[D_Main_Appdelegate payView] setUpHeadView:model.orderid];
    [D_Main_Appdelegate payView].orderNumber = model.orderid;
    [D_Main_Appdelegate payView].price = model.total;
    [D_Main_Appdelegate payView].block =^{
        [self.waitPayArry removeObject:model];
        model.status = @"200";
        [self.ReceivingArry addObject:model];
        [self.orderTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    };
}

//马上付钱ReC
- (void)quicklyPayManyReC:(ReceiptTableViewCell *)childBaseCell
{
    NSIndexPath *indexPath = [self.orderTableView indexPathForCell:childBaseCell];
    indentModel *model = self.dataArray[indexPath.row];
    [D_Main_Appdelegate showPayView];
//    [[D_Main_Appdelegate payView] setUpHeadView:model.orderid];
    [D_Main_Appdelegate payView].orderNumber = model.orderid;
    [D_Main_Appdelegate payView].price = model.total;
    [D_Main_Appdelegate payView].block =^{
        [self.waitPayArry removeObject:model];
        model.status = @"200";
        [self.ReceivingArry addObject:model];
        [self.orderTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    };
}

- (void)querenGoods:(childBaseTableViewCell *)childBaseCell
{
    NSIndexPath *indexPath = [self.orderTableView indexPathForCell:childBaseCell];
    indentModel *model = self.dataArray[indexPath.row];
    [BPhttpTool get:[NSString stringWithFormat:@"%@order/confirmgoods/id/%@",BPhttp,model.orderid] params:nil success:^(id responseObj) {
        NSDictionary *dic = responseObj;
        if ([dic[@"status"] intValue] == 1) {
            [MBProgressHUD showSuccess:@"确认收货"];
            model.status = @"500";
            [self.ReceivingArry removeObject:model];
            [self.showProductArry addObject:model];
            [self.orderTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
        }
    } failure:^(NSError *error) {
        BPLog(@"确认收货失败");
    }];

}

// ReC
- (void)querenGoodsReC:(ReceiptTableViewCell *)childBaseCell
{
    NSIndexPath *indexPath = [self.orderTableView indexPathForCell:childBaseCell];
    indentModel *model = self.dataArray[indexPath.row];
    [BPhttpTool get:[NSString stringWithFormat:@"%@order/confirmgoods/id/%@",BPhttp,model.orderid] params:nil success:^(id responseObj) {
        NSDictionary *dic = responseObj;
        if ([dic[@"status"] intValue] == 1) {
            [MBProgressHUD showSuccess:@"确认收货"];
            model.status = @"500";
            [self.ReceivingArry removeObject:model];
            [self.showProductArry addObject:model];
            [self.orderTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
        }
    } failure:^(NSError *error) {
        BPLog(@"确认收货失败");
    }];
    
}




//查看物流
- (void)lookWUliu:(childBaseTableViewCell *)childBaseCell
{
    NSIndexPath *indexPath = [self.orderTableView indexPathForCell:childBaseCell];
    indentModel *model = self.dataArray[indexPath.row];
    wuliuVC *wuliu = [[wuliuVC alloc] init];
    wuliu.webName = @"logistics.html";
    wuliu.title = @"查看物流";
    wuliu.orderID = model.orderid;
    [self.navigationController pushViewController:wuliu animated:YES];
}

//查看物流Rec
- (void)lookWUliuReC:(ReceiptTableViewCell *)childBaseCell
{
    NSIndexPath *indexPath = [self.orderTableView indexPathForCell:childBaseCell];
    indentModel *model = self.dataArray[indexPath.row];
    wuliuVC *wuliu = [[wuliuVC alloc] init];
    wuliu.webName = @"logistics.html";
    wuliu.title = @"查看物流";
    wuliu.orderID = model.orderid;
    [self.navigationController pushViewController:wuliu animated:YES];
}



- (void)quickShaidan:(childBaseTableViewCell *)childBaseCell
{
    NSIndexPath *indexPath = [self.orderTableView indexPathForCell:childBaseCell];
    indentModel *model = self.dataArray[indexPath.row];
    shaidanViewController *shaidan = [[shaidanViewController alloc] init];
    shaidan.orderID = model.iD;
    shaidan.block = ^(){
        model.isshare = @"1";
        //[self.dataArray removeObject:model];
        [self.showProductArry removeObject:model];
        [self.receivedArry addObject:model];
        [self.orderTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    };
    [self.navigationController pushViewController:shaidan animated:YES];
}

// Rec
- (void)quickShaidanReC:(ReceiptTableViewCell *)childBaseCell
{
    NSIndexPath *indexPath = [self.orderTableView indexPathForCell:childBaseCell];
    indentModel *model = self.dataArray[indexPath.row];
    shaidanViewController *shaidan = [[shaidanViewController alloc] init];
    shaidan.orderID = model.iD;
    shaidan.block = ^(){
        model.isshare = @"1";
        //[self.dataArray removeObject:model];
        [self.showProductArry removeObject:model];
        [self.receivedArry addObject:model];
        [self.orderTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    };
    [self.navigationController pushViewController:shaidan animated:YES];
}



- (void)shanchuCell:(childBaseTableViewCell *)childBaseCell
{
    NSIndexPath *indexPath = [self.orderTableView indexPathForCell:childBaseCell];
    indentModel *model = self.dataArray[indexPath.row];
    int workID = [model.iD intValue];
    if (workID != 0) {
        [BPhttpTool get:[NSString stringWithFormat:@"%@order/delete/id/%d",BPhttp,workID] params:nil success:^(id responseObj) {
            NSDictionary *dic = responseObj;
            if ([dic[@"status"] intValue] == 1) {
                [MBProgressHUD showSuccess:@"删除成功"];
            }
            
            
        } failure:^(NSError *error) {
            
        }];
    }
    
    [self.dataArray removeObjectAtIndex:indexPath.row];
    [self.orderTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

// Rec
- (void)shanchuCellReC:(ReceiptTableViewCell *)childBaseCell
{
    NSIndexPath *indexPath = [self.orderTableView indexPathForCell:childBaseCell];
    indentModel *model = self.dataArray[indexPath.row];
    int workID = [model.iD intValue];
    if (workID != 0) {
        [BPhttpTool get:[NSString stringWithFormat:@"%@order/delete/id/%d",BPhttp,workID] params:nil success:^(id responseObj) {
            NSDictionary *dic = responseObj;
            if ([dic[@"status"] intValue] == 1) {
                [MBProgressHUD showSuccess:@"删除成功"];
            }
            
            
        } failure:^(NSError *error) {
            
        }];
    }
    
    [self.dataArray removeObjectAtIndex:indexPath.row];
    [self.orderTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}


- (void)top:(UIButton *)topp{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
